home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2007 July & August
/
PCWorld_2007-07-08_cd.bin
/
komunikace
/
maxthon
/
mcombo.exe
/
Plugin
/
Del.icio.us Sidebar
/
scripts
/
pageScript.js
< prev
Wrap
Text File
|
2006-09-02
|
7KB
|
321 lines
/**************************
Del.icio.us Sidebar
By Neo101
Version 1.1.0
**************************/
var openImageSrc = "images/folderOpen.gif"
var closedImageSrc = "images/folderClosed.gif"
var openImg = new Image()
openImg.src = openImageSrc
var closedImg = new Image()
closedImg.src = closedImageSrc
var currentlyOpenFolder = null
function showBranch(branch, i){
var objBranch = document.getElementById(branch).style;
if(objBranch.display == "block"){
objBranch.display = "none";
currentlyOpenFolder = null
}
else {
objBranch.display = "block";
if(i != null){
currentlyOpenFolder = i
}
}
}
function swapFolder(img){
objImg = document.getElementById(img);
if(objImg.src.indexOf(closedImageSrc) != -1){
objImg.src = openImg.src;
}
else{
objImg.src = closedImg.src;
}
}
function expandCollapse(i, element){
if(currentlyOpenFolder != null && currentlyOpenFolder != i){
var folder = currentlyOpenFolder
showBranch('branch' + folder)
swapFolder('folder' + folder)
}
showBranch('branch' + i, i)
swapFolder('folder' + i)
}
function showLink(link){
external.get_tab(SECURITY_ID, external.cur_sel).window.status = link
}
function hideLink(){
external.get_tab(SECURITY_ID, external.cur_sel).window.status = ''
}
function enterKeyPress() {
if (window.event.keyCode == 13){
save()
}
}
function showAddFavoriteDialog(type){
var CONFIG_WIDTH = '500'
var CONFIG_HEIGHT = '300'
var left = ( screen.width/2 ) - ( CONFIG_WIDTH / 2 )
var top = ( screen.height/2 ) - ( CONFIG_HEIGHT / 2 )
var list = 'status:0;help:0;scroll:0;resizable:0;dialogHeight:'+CONFIG_HEIGHT+'px;dialogWidth:'+CONFIG_WIDTH+
'px;center:0;dialogLeft:'+left+'px;dialogTop:'+top+'px'
if(type == 'add'){
isAddFavorite = true
} else {
isAddFavorite = false
}
var dialog = window.showModalDialog('addFavorite.html', window, list)
}
function addFavorite(form){
var url = form.url.value
var description = form.description.value
var extended = form.notes.value
var tags = form.tags.value
var shared = form.shared.checked
if(url == '' || description == ''){
alert('Please fill in the URL and description')
return false
}
var postURL = baseURL + 'posts/add?'
postURL += 'description=' + encodeURIComponent( description )
postURL += '&url=' + url
postURL += '&extended=' + encodeURIComponent( extended )
postURL += '&tags=' + encodeURIComponent( tags )
if(shared == false){
postURL += '&shared=no'
}
loadXMLDoc(postURL, 'postFavorite', onResponsePostFavorite)
return true
}
function search(keyword){
if(currentlyOpenFolder != null){
var folder = currentlyOpenFolder
showBranch('branch' + folder)
swapFolder('folder' + folder)
}
if(keyword.length < 2){
//document.getElementById('favorites').innerHTML = favoritesHTML
var nodes = document.getElementsByTagName('div')
for(var i=0; i<nodes.length; i++){
var node = nodes[i]
if( node.className == 'trigger' ) {
node.style.display = ''
}
else if( node.className == 'branch' ){
node.style.display = 'none'
}
else if( node.className == 'linkDiv' ){
node.style.display = ''
}
}
}
if(keyword.length < 2){
return
}
keyword = keyword.replace(/([\+\?\*\[\]\.\(\)])/g,'\\$1')
var re = new RegExp(keyword, 'i')
var foundArray = new Array()
var nodes = document.getElementsByTagName('div')
for(var i=0; i<nodes.length; i++){
var node = nodes[i]
if( node.className == 'trigger' ) {
node.style.display = 'none'
}
else if( node.className == 'branch' ){
node.style.display = 'block'
}
if( node.className != 'linkDiv' ){
continue
}
else if( textInArray(node.innerHTML, foundArray) ){
node.style.display = 'none'
continue
}
var match = re.exec(node.childNodes(0).href)
if(match == null){
match = re.exec(node.childNodes(0).title)
}
if(match == null){
match = re.exec(node.childNodes(0).innerText)
}
if(match == null){
node.style.display = 'none'
} else {
foundArray.push(node.innerHTML)
node.style.display = ''
}
}
}
function textInArray(item, array){
for(var i=0; i<array.length; i++){
if( item == array[i] ){
return true
}
}
return false
}
var contextMenuObj = new ContextMenu()
function ContextMenu(){
this.x = 0
this.y = 0
this.element = null
this.id = null
}
function setMouseCoords() {
contextMenuObj.x = event.clientX;
contextMenuObj.y = event.clientY;
}
document.onmousemove = function(){
setMouseCoords()
}
function showContextMenu(element) {
hideContextMenu()
contextMenuObj.element = element
if(element.className == 'trigger'){
contextMenuObj.id = 'contextMenuFolder'
}
else {
contextMenuObj.id = 'contextMenuFavorite'
}
doShowContextMenu(contextMenuObj.id)
}
function doShowContextMenu(elementId) {
var contextMenu = document.getElementById(elementId);
setVisible(elementId)
var clientWidth = ( document.documentElement.clientWidth == 0) ? document.body.clientWidth : document.documentElement.clientWidth
var clientHeight = ( document.documentElement.clientHeight == 0) ? document.body.clientHeight : document.documentElement.clientHeight
if(contextMenuObj.x+contextMenu.offsetWidth + 10 > clientWidth){
contextMenu.style.left = (contextMenuObj.x-contextMenu.offsetWidth + document.documentElement.scrollLeft) + "px";
}
else{
contextMenu.style.left = contextMenuObj.x + 10 + "px";
}
if(contextMenuObj.y+contextMenu.offsetHeight + 5 > clientHeight){
contextMenu.style.top = contextMenuObj.y - contextMenu.offsetHeight + document.documentElement.scrollTop - 10 + "px";
}
else{
contextMenu.style.top = contextMenuObj.y + document.documentElement.scrollTop + 10 + "px";
}
}
function hideContextMenu() {
setInvisible(contextMenuObj.id)
}
function setInvisible( elementID ){
if(elementID == null){
return
}
document.getElementById( elementID ).style.display = 'none'
}
function setVisible( elementID ){
if(elementID == null){
return
}
document.getElementById( elementID ).style.display = 'block'
}
document.onclick=function(){
hideContextMenu()
}
function openAll(){
var element = contextMenuObj.element
var nodes = element.nextSibling.getElementsByTagName('a')
for(var i=0; i<nodes.length; i++){
//external.m2_callerName(SECURITY_ID, PLUGIN_NAME)
window.open(nodes[i].href)
}
}
function editFavoriteClick(){
var element = contextMenuObj.element
var url = element.childNodes(0).href
editElement = element.childNodes(0)
if(editElement == null){
showError('Error 295: can\'t find URL')
return
}
showAddFavoriteDialog('edit')
}
function deleteFavoriteClick(){
var element = contextMenuObj.element
var url = element.childNodes(0).href
var confirmation = confirm('Are you sure you would like to delete this favorite?\n' + url)
if(confirmation == false){
return
}
deleteFavorite(url)
}
function moreInfoFavoriteClick(){
var element = contextMenuObj.element
var url = 'http://del.icio.us/url/' + element.childNodes(0).hashCode
//external.m2_callerName(SECURITY_ID, PLUGIN_NAME)
window.open(url)
}